﻿using ZYCommon;
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;

namespace TextEditor
{

    /// <summary>
    /// 元素属性设置
    /// </summary>
    public class KBTagProvider : SmartTagProvider
    {
        public override void GetCommands(ArrayList myList)
        {
            ZYTextCheck element = base.Element as ZYTextCheck;
            if (element == null)
            {
                element = base.Element.Parent as ZYTextCheck;
            }
            myList.Add(new SmartTagItem(this, 3, element.check == "Y", "选中/取消"));
            myList.Add(new SmartTagItem(this, 0, "修改ID [" + element.ID + "] 为..."));
            myList.Add(new SmartTagItem(this, 1, "修改Name [" + element.Name + "] 为..."));
            myList.Add(new SmartTagItem(this, 2, "修改文本"));
            //myList.Add(new SmartTagItem(this, 2, "&D  设置默认显示文本 " + element.DisplayName + " 为..."));
            //myList.Add(new SmartTagItem(this, 3, "&C  清空内容"));
            //myList.Add(new SmartTagItem(this, 9, "&C  设置文本颜色..."));
            //myList.Add(new SmartTagItem("-"));
            //myList.Add(new SmartTagItem(this, 1, element.Multiple, "&M  多选列表"));
            //myList.Add(new SmartTagItem(this, 8, element.KeyField, "&K  设置为关键字段"));
            //if (base.OwnerControl.KBTreeView != null)
            //{
            //    myList.Add(new SmartTagItem(this, 2, "&F  在知识库列表中定位"));
            //}
        }

        public override Point GetPos()
        {
            ZYTextSelect element = base.Element as ZYTextCheck;
            if (element == null)
            {
                element = base.Element.Parent as ZYTextCheck;
            }
            if (element != null)
            {
                return new Point(element.RealLeft, (element.RealTop - base.OwnerControl.SmartTagSize()) - 2);
            }
            return Point.Empty;
        }

        public override bool HandleCommand(SmartTagItem item)
        {
            ZYTextCheck element = base.Element as ZYTextCheck;
            if (element == null)
            {
                element = base.Element.Parent as ZYTextCheck;
            }
            switch (item.ID)
            {
                case 0:
                    {
                        string str2 = dlgInputBox.InputBox("请输入ID", "修改ID", element.ID);
                        if (str2 != null)
                        {
                            element.ID = str2;
                        }
                        break;
                    }
                case 1:
                    {
                        string str2 = dlgInputBox.InputBox("请输入Name", "修改Name", element.Name);
                        if (str2 != null)
                        {
                            element.Name = str2;
                        }
                        break;
                    }
                case 2:
                    {
                        string str2 = dlgInputBox.InputBox("请输入文本内容", "修改文本内容", element.Text);
                        if (str2 != null)
                        {
                            element.Text = str2;
                            element.RefreshSize();
                            base.OwnerDocument.RefreshElements();
                            base.OwnerDocument.RefreshLine();
                            base.OwnerDocument.Refresh();
                            base.OwnerDocument.Modified = true;
                        }
                        break;
                    }
                case 3:
                    element.check = element.check == "Y" ? "N" : "Y";
                    element.OwnerDocument.RefreshElement(element);
                    break;
                //        case 0:
                //        {
                //            if (element == null)
                //            {
                //                goto Label_0308;
                //            }
                //            KB_List kBList = ZYKBBuffer.Instance.GetKBList(element.ListSource);
                //            if ((kBList == null) || !kBList.isFixItem())
                //            {
                //                MessageBox.Show(base.OwnerControl, "本列表无法添加项目", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                //                break;
                //            }
                //            if (base.OwnerDocument.DataSource.DBConn.CanUpdate)
                //            {
                //                string strData = dlgInputBox.InputBox("请输入新项目的内容", "系统提示", "新增项目");
                //                if (!StringCommon.isBlankString(strData))
                //                {
                //                    strData = strData.Trim();
                //                    foreach (KB_Item item2 in kBList.Items)
                //                    {
                //                        if (item2.ItemText == strData)
                //                        {
                //                            MessageBox.Show(base.OwnerControl, "已经存在列表项目[ " + strData + " ]", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                //                            return false;
                //                        }
                //                    }
                //                    KB_Item myRecord = kBList.NewItem(strData);
                //                    base.OwnerDocument.DataSource.DBConn.UpdateRecordAuto(myRecord);
                //                }
                //                break;
                //            }
                //            MessageBox.Show(base.OwnerControl, "无法更新数据库,因此无法新增项目!", "系统提示");
                //            return false;
                //        }
                //        case 1:
                //            if (element == null)
                //            {
                //                goto Label_0308;
                //            }
                //            element.Multiple = !element.Multiple;
                //            return true;

                //        case 2:
                //            if ((element == null) || (base.OwnerControl.KBTreeView == null))
                //            {
                //                goto Label_0308;
                //            }
                //            base.OwnerControl.KBTreeView.SelectedKBList = ZYKBBuffer.Instance.GetKBList(element.ListSource);
                //            return true;

                //        case 3:
                //        {
                //            //string str2 = dlgInputBox.InputBox("请输入新的显示名称", "修改显示名称", element.DisplayName);
                //            //if (str2 != null)
                //            //{
                //            //    element.DisplayName = str2;
                //            //    element.UpdateText();
                //            //    element.RefreshSize();
                //            //    base.OwnerDocument.RefreshElements();
                //            //    base.OwnerDocument.RefreshLine();
                //            //    base.OwnerDocument.Refresh();
                //            //    base.OwnerDocument.Modified = true;
                //            //}
                //            goto Label_0308;
                //        }
                //        case 4:
                //            element.Text = "";
                //            element.Value = "";
                //            element.UpdateText();
                //            element.RefreshSize();
                //            base.OwnerDocument.RefreshElements();
                //            base.OwnerDocument.RefreshLine();
                //            base.OwnerDocument.Refresh();
                //            base.OwnerDocument.Modified = true;
                //            goto Label_0308;

                //        case 8:
                //            element.KeyField = !element.KeyField;
                //            goto Label_0308;
                //        case 9:
                //            using (ColorDialog dialog = new ColorDialog())
                //            {
                //                dialog.Color = element.TempForeColor;
                //                if (dialog.ShowDialog() == DialogResult.OK)
                //                {

                //                    element.TempForeColor = dialog.Color;
                //                    element.ForeColor = dialog.Color;
                //                    base.OwnerDocument.Refresh();
                //                }
                //            }
                //            goto Label_0308;
                //        default:
                //            goto Label_0308;
                //    }
                //    return true;
                //Label_0308:
                //    return false;
            }
            return true;
        }

        public override bool isEnable()
        {
            if (base.OwnerDocument.Content.SelectLength != 0)
            {
                return false;
            }
            if (base.OwnerDocument.Us.InpatientInfo != null)
            {
                return false;
            }
            return ((base.OwnerDocument.Content.CurrentElement is ZYTextCheck) || (base.OwnerDocument.Content.CurrentElement.Parent is ZYTextCheck));
        }

        public override int ImageIndex
        {
            get
            {
                return 2;
            }
        }
    }
}

